/**
 * @InitViewEnd.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2012 ASFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:ASFrame AStruts2
 * <br>Date:2012-7-5
 */
package com.asframe.astruts2.mvc.controller
{
	import com.asframe.astruts2.beans.MediatorBean;
	import com.asframe.astruts2.beans.ViewBean;
	import com.asframe.astruts2.interfaces.IInitViewEnd;
	import com.asframe.astruts2.mvc.mediator.IMediator;
	import com.asframe.astruts2.mvc.view.IMvcView;
	
	/**
	 * view被初始化完成了，这里是进行扩展，mvc框架的独特实现
	 * @author sodaChen
	 * @Date:2012-7-5
	 */
	public class InitViewEnd implements IInitViewEnd
	{
		public function InitViewEnd()
		{
		}
		
		public function initViewEnd(viewBean:ViewBean):void
		{
			if(viewBean.view is IMvcView)
			{
				var view:IMvcView = viewBean.view;
				if(viewBean.autoInit)
				{
					view.init();
				}
			}
			
			//调用代理的初始化函数
			var len:int = viewBean.mediators.length;
			var mediatorBean:MediatorBean = null;
			var mediator:IMediator = null;
			for (var i:int = 0; i < len; i++) 
			{
				mediatorBean = viewBean.mediators[i];
				if(mediatorBean.mediator is IMediator)
				{
					mediator = IMediator(mediatorBean.mediator);
					mediator.setView(view);
					mediator.init();
				}
			}
		}
	}
}
